﻿var NUM = 0;
var num = 0;
var strIds = [];
var INTERVAL = 2000;//曲线间时间间隔
var selectedRadioValue = "rblQushi";
var inter = null; //趋势描图数组指示器
var drawCan = "HYGGL"; //描图参数
var timer1 = null;
var n = 1;
var jj = 0;
var qushi_num = -1; //趋势描图时的取消上一条的编号
var start_next = 0; //标示点击下一条按钮时暂停按钮是否处于停在状态
var b = true; //标示曲线颜色的，true为单色，false为多色；只有对比描图时才会是多色

var selectedIds = new Array();

//********************初始化页面**********************//
function initialBind() {
    $("#div_HYGGL").show();
    INTERVAL = 0;
    selectedRadioValue = 'rblSingle';
    $("#checkboxall").attr("disabled", true);
    $("#checkboxall").attr("checked", false);

    $("#amount").val("2");


}




//********************描图通用方法**********************//

///将点数转换成度数
function getArray(data) {
    if (drawCan == "SGT") {
        return data;
    }
    else {

        var len = data.length;
        var array = new Array(len);

        for (var i = 0; i < len; i++) {
            var xValue = 360 / len * (i + 1);
            array[i] = [xValue, data[i]];   

        }
        return array;
    }
    return array;

}

///清空描图区域
function canselSpline() {
    var chart = $('#container').highcharts();
    if (chart.series.length) {//清空描图区域
        var len = chart.series.length;
        for (var i = 0; i < len; i++) {
            chart.series[0].remove();
        }
    }

}
///通过描图参数选择调用不同的计算特征值的方法
function switchDrawCan(data) {
    switch (drawCan) {
        case "HYGGL": getHYGGL(data); break;
        case "HWGGL": getHWGGL(data); break;
        case "HSZGL": getHSZGL(data); break;
        case "HGLYS": getHGLYS(data); break;
        case "ADL": getADL(data); break;
        case "ADY": getADY(data); break;
        case "DJSCNJ": getDJSCNJ(data); break;
        default: getHYGGL(data);
    }
}
///描一条曲线
function drawSingleSpline(ID) {
    $.ajax({
        url: 'ajax.ashx',
        type: 'get',
        dataType: 'xml', //这里可以不写，但千万别写text或者html!!! 
        data: { id: ID, field: drawCan },
        timeout: 2000,
        cache: false,
        error: function (xml) {
            alert('数据有错误' + xml);
        },
        success: function (xml) {
            var data1 = [];
            $(xml).find("tables").children().each(function () {
                if (drawCan == "SGT") {
                    var l = $(this).children("l").text();
                    var xdzh = $(this).children("XDZH").text();
                    data1.push([Number(l), Number(xdzh)]);
                } else {
                    var l = $(this).children("l").text();
                    data1.push(Number(l));
                }
            });
            if (drawCan != "SGT") {
                switchDrawCan(data1);
            }
            var chart = $('#container').highcharts();
            if (!b) {
                chart.addSeries({
                    data: getArray(data1)
                });
            }
            else {
                chart.addSeries({
                    data: getArray(data1),
                    color: '#0000AA'
                });
            }
            p.attr("title", chart.series.length - 1);
          
        }
    });
}
///取消一条曲线
function cancelSingleSpline() {
    var chart = $('#container').highcharts();
       

    if (selectedRadioValue == "rblQushi") {
        chart.series[0].remove();
    }
    else if (selectedRadioValue == "rblSingle") {
        if (chart.series.length > 1) {
            chart.series[0].remove();
        }
    }
    else {

        if (chart.series.length > 0) {

            $("#GridView1 .checkone :input").each(function () {
                var str1 = $(this).attr('title');
                if (Number(str1) != NaN) {
                    if (Number(str1) > num) {
                        $(this).attr('title', Number(str1) - 1);
                    }
                }
            });



            chart.series[num].remove();
        }
    }
}
///描出所有选中的曲线
function drawSpline() {
    strIds = []; //ID序列
    NUM = 0;
    //    canselSpline(); //清空描图区域

    $("#GridView1 .checkone :input").each(function () {//描出选中的曲线
        if ($(this).attr('checked') == true) {
            NUM++;
            strIds.push($(this).parent().parent().parent().find(".jh").attr('value'));
        }
    });

    n = 1;
    if (NUM > 0) {
        var timer1 = setInterval(function () {
            canselSpline();
            drawSingleSpline(strIds[n - 1], drawCan);
            if (n++ >= NUM) {//跳出循环
                n = 1;
                clearInterval(timer1);
            }
        }, INTERVAL);
    }

}

///趋势自动播放描图
function drawQushiSpline() {

    strIds = []; //ID序列
    NUM = 0;
    jj = 0; //淡出效果时的标示
    var conf = 0; //哨兵
    $("#GridView1 .checkone :input").each(function () {
        //        if ($(this).attr('checked') == true) {
        //            if ($(this).parent().parent().parent().find(".jh").attr('title') == inter.parent().parent().parent().find(".jh").attr('title')) {
        //                conf = 1;
        //            }
        //            if (conf == 1) {
        //                NUM++;
        //                strIds.push($(this).parent().parent().parent().find(".jh").attr('title'));
        //            }
        //        }

        if ($(this).parent().parent().parent().find(".jh").attr('value') == inter.parent().parent().parent().find(".jh").attr('value')) {
            conf = 1;
        }
        if (conf == 1 && $(this).attr('checked') == true) {
            NUM++;
            strIds.push($(this).parent().parent().parent().find(".jh").attr('value'));
        }

    });

    n = 1;
    if (NUM > 0) {
        timer1 = setInterval(function () {
            start_next = 1;
            if (qushi_num != -1) {

                var chart = $('#container').highcharts();
                if (chart.series.length > 1) {
                    chart.series[0].remove();
                    jj--;
                }
                $('g.highcharts-series').eq(jj).fadeOut(1500); //highcharts-markers highcharts-tracker
                $('g.highcharts-markers highcharts-tracker').eq(jj++).fadeOut(1500);

            }
            qushi_num = Number(inter.attr('title'));
            $("#GridView1 .checkone :input:checked").each(function () {//取消非当前选中复选框
                if ($(this).parent().parent().parent().find(".jh").attr('value') == strIds[n - 1]) {
                    inter = $(this);
                    inter.parent().parent().parent().addClass('selected').siblings().removeClass('selected').end()//当前行变色
                }
            });
            drawSingleSpline(strIds[n - 1], drawCan);


            if (n++ >= NUM) {//跳出循环
                clearInterval(timer1);
                start_next = 0;
                $('#btn_start').css("background", "url(../../images/DrawMult1/bf03.png) no-repeat");
                inter = null;

            }
        }, INTERVAL);
    }

}
///清空GridView的复选框
function canselView() {

    $("#GridView1 .checkone :input").each(function () {//取消所有复选框
        $(this).attr("checked", false);
    });
}
///清空GridView的非当前选中的复选框
function canselNoIndexView() {

    $("#GridView1 .checkone :input:checked").each(function () {//取消非当前选中复选框
        if ($(this).parent().parent().parent().find(".jh").attr('value') != inter.parent().parent().parent().find(".jh").attr('value')) {
            $(this).attr("checked", false);
        }
    });
}
///全选GridView的复选框
function checkAllView() {
    $("#GridView1 .checkone :input").each(function () {//选中所有复选框
        $(this).attr("checked", true);
    });
}
$(function () {
    $("#slider").slider({
        //        value: 2,
        min: 0,
        max: 10,
        step: 1,
        slide: function (event, ui) {
            $("#amount").val(ui.value);
        }
    });
});
//********************特征值计算通用方法**********************//
///求一组数据中的最大值
function getValueMax(data) {
    var max = data[0];
    for (i = 1; i < data.length; i++) {
        if (data[i] >= max) max = data[i];
    }
    return max;
}
///求一组数据的平均值
function  getValueAveg(data) {
    var i = 0;
    var aveg = 0;
    for (i = 0; i < data.length; i++) {
        aveg += data[i];
    }
    aveg = aveg / i;
    return aveg;
}
///求一组数据的所有正数平均值
function getPosiValueAveg(data) {
    var i = 0;
    var aveg = 0;
    for (i = 0; i < data.length; i++) {
        if (data[i] > 0){
            aveg += data[i];
        }
    }
    aveg = aveg / i;
    return aveg;
}
///求一组数据的所有负数平均值
function getNageValueAveg(data) {
    var i = 0;
    var aveg = 0;
    for (i = 0; i < data.length; i++) {
        if (data[i] < 0) {
            aveg += data[i];
        }
    }
    aveg = aveg / i;
    return aveg;
}
///有功功率特征值计算方法
function getHYGGL(data) {
    updata=[];//上行数据
    downdata=[];//下行数据
    var upmax;//上行有功最大值
    var downmax;//下行有功最大值
    var maxbalance; //有功最大值平衡度
    var upaveg; //上行有功平均值
    var downaveg; //下行有功平均值
    var avegbalance; //有功平均值平衡度
    var nagerata; //有功负值率
    var pzrata; //有功偏置率
    var posivalue = 0; //日有功正能耗
    var nagevalue = 0; //日有功负能耗

    //提取上行和下行数据
    for (i = 0; i < data.length; i++) {
        if (i < data.length/2) {
            updata.push(data[i]);
        }
        else {
            downdata.push(data[i]);
        }
    }
    //最大值
    upmax = getValueMax(updata);
    upmax = Math.round((upmax +0.001)* Math.pow(10, 2)) / Math.pow(10, 2);
    downmax = getValueMax(downdata);
    downmax = Math.round((downmax +0.001)* Math.pow(10, 2)) / Math.pow(10, 2);
    maxbalance = downmax / upmax;
    maxbalance = Math.round((maxbalance +0.001)* Math.pow(10, 2)) / Math.pow(10, 2);
    $("#text_sxygzdz").val(upmax);
    $("#text_xxygzdz").val(downmax);
    $("#text_ygzdzphd").val(maxbalance);
    //平均值
    upaveg = getPosiValueAveg(updata);
    upaveg = Math.round((upaveg +0.001)* Math.pow(10, 2)) / Math.pow(10, 2);
    downaveg = getPosiValueAveg(downdata);
    downaveg = Math.round((downaveg +0.001)* Math.pow(10, 2)) / Math.pow(10, 2);
    avegbalance = downaveg / upaveg;
    avegbalance = Math.round((avegbalance +0.001)* Math.pow(10, 2)) / Math.pow(10, 2);
    $("#text_sxygpjz").val(upaveg);
    $("#text_xxygpjz").val(downaveg);
    $("#text_ygpjzphd").val(avegbalance);
    //负值率、日有功正能耗、日有功负能耗
    
    for (var i = 0; i < data.length; i++) {
        if (data[i] > 0) {
            posivalue += data[i];
        }
        else {
            nagevalue += data[i];
        }

    }
    posivalue = (posivalue / 256) * 24;
    posivalue = Math.round((posivalue +0.001)* Math.pow(10, 2)) / Math.pow(10, 2);
    nagevalue = Math.abs((nagevalue / 256) * 24);
    nagevalue = Math.round((nagevalue +0.001)* Math.pow(10, 2)) / Math.pow(10, 2);
    nagerata = nagevalue / (nagevalue + posivalue);
    nagerata = Math.round((nagerata +0.001)* Math.pow(10, 2)) / Math.pow(10, 2);
    $("#text_ygfzl").val(nagerata);
    $("#text_ygznh").val(posivalue);
    $("#text_ygfnh").val(nagevalue);
    //偏置率
    var upmin = updata[0];
    var downmin = downdata[0];
    for (var i = 1; i < updata.length; i++) {
        if (updata[i] < upmin) upmin = updata[i];
    }
    for (var j = 1; j < downdata.length; j++) {
        if (downdata[j] < downmin) downmin = downdata[j];
    }
    if (upmin == 0) {
        pzrata = 0;
    }
    else {
        pzrata = downmin / upmin;
    }
    pzrata = Math.round((pzrata +0.001)* Math.pow(10, 2)) / Math.pow(10, 2);
    $("#text_ygpzl").val(pzrata);

       

}
///无功功率特征值计算方法
function getHWGGL(data) {
    var max; //无功功率最大值
    var aveg; //无功平均值
    var wgnh = 0; //无功能耗
    max = getValueMax(data);
    max = Math.round((max +0.001)* Math.pow(10, 2)) / Math.pow(10, 2);
    aveg = getValueAveg(data);
    aveg = Math.round((aveg +0.001)* Math.pow(10, 2)) / Math.pow(10, 2);
    for (var i = 0; i < data.length; i++) {
        wgnh += data[i];
    }
    wgnh = (wgnh / 256) * 24;
    wgnh = Math.round((wgnh +0.001)* Math.pow(10, 2)) / Math.pow(10, 2);
    $("#text_wgzdz").val(max);
    $("#text_wgpjz").val(aveg);
    $("#text_wgnh").val(wgnh);

    
}
///视在功率特征值计算方法
function getHSZGL(data) {
    var max; 
    var aveg;
    max = getValueMax(data);
    max = Math.round((max +0.001)* Math.pow(10, 2)) / Math.pow(10, 2);
    aveg = getValueAveg(data);
    aveg = Math.round((aveg +0.001)* Math.pow(10, 2)) / Math.pow(10, 2);
    $("#text_szglzdz").val(max);
    $("#text_szglpjz").val(aveg);

}
///功率因数特征值计算方法
function getHGLYS(data) {
    var max;
    var aveg;
    max = getValueMax(data);
    max = Math.round((max+0.00001) * Math.pow(10, 4)) / Math.pow(10,4);
    aveg = getValueAveg(data);
    aveg = Math.round((aveg+0.00001) * Math.pow(10, 4)) / Math.pow(10, 4);
    $("#text_glyszdz").val(max);
    $("#text_glyspjz").val(aveg);
}
///电流特征值计算方法
function getADL(data) {
    updata = []; //上行数据
    downdata = []; //下行数据
    var upmax; //上行最大值
    var downmax; //下行最大值
    var maxbalance; //最大值平衡度
    //提取上行和下行数据
    for (i = 0; i < data.length; i++) {
        if (i < data.length / 2) {
            updata.push(data[i]); 
        }
        else {
            downdata.push(data[i]);
        }
    }
    //最大值
    upmax = getValueMax(updata);
    upmax = Math.round((upmax +0.001)* Math.pow(10, 2)) / Math.pow(10, 2);
    downmax = getValueMax(downdata);
    downmax = Math.round((downmax +0.001)* Math.pow(10, 2)) / Math.pow(10, 2);
    maxbalance = downmax / upmax;
    maxbalance = Math.round((maxbalance +0.001)* Math.pow(10, 2)) / Math.pow(10, 2);
    $("#text_sxdlzdz").val(upmax);
    $("#text_xxdlzdz").val(downmax);
    $("#text_dlzdzphd").val(maxbalance);
}
///电压特征值计算方法
function getADY(data) {
    var max; 
    var aveg;
    max = getValueMax(data);
    max = Math.round((max +0.001)* Math.pow(10, 2)) / Math.pow(10, 2);
    aveg = getValueAveg(data);
    aveg = Math.round((aveg +0.001)* Math.pow(10, 2)) / Math.pow(10, 2);
    $("#text_dyzdz").val(max);
    $("#text_dypjz").val(aveg);
}
///扭矩特征值计算方法
function getDJSCNJ(data) {
    updata = []; //上行数据
    downdata = []; //下行数据
    var upsqrt=0; 
    var downsqrt=0; 
    var balance=0; //平衡度
    var nagerata=0; //负值率
    var pzrata=0; //偏置率
    //提取上行和下行数据
    for (i = 0; i < data.length; i++) {
        if (i < data.length / 2) {
            updata.push(data[i]);
        }
        else {
            downdata.push(data[i]);
        }
    }
    //上行均方根
    var i=0;
    for (i = 0; i < updata.length; i++) {
        upsqrt = upsqrt+(updata[i])*(updata[i]);
    }
    upsqrt = Math.sqrt(upsqrt / i);
    upsqrt = Math.round((upsqrt +0.001)* Math.pow(10, 2)) / Math.pow(10, 2);
    $("#text_sxnjzfg").val(upsqrt);
    //下行均方根
    var j = 0;
    for (j = 0; j < downdata.length; j++) {
        downsqrt = downsqrt + (downdata[j]) * (downdata[j]);
    }
    downsqrt = Math.sqrt(downsqrt / j);
    downsqrt = Math.round((downsqrt +0.001)* Math.pow(10, 2)) / Math.pow(10, 2);
    $("#text_xxnjjfg").val(downsqrt);
    //平衡度
    balance = downsqrt / upsqrt;
    balance = Math.round((balance +0.001)* Math.pow(10, 2)) / Math.pow(10, 2);
    $("#txt_njjfgphd").val(balance);
    //偏置率
    var max = getValueMax(updata);
    var min = updata[0];
    for (i = 0; i < updata.length; i++) {
        if (updata[i] < min) min = updata[i];
    }
    if (max - min != 0) {
        pzrata = (updata[updata.length - 1] - updata[0]) / (max - min);
    }
    else {
        pzrata = 1;
    }
    pzrata = Math.round((pzrata +0.001)* Math.pow(10, 2)) / Math.pow(10, 2);
    $("#txt_njpzl").val(pzrata);
    //负值率
    var posimult = 0;
    var nagemult = 0;
    for (i = 0; i < data.length; i++) {
        if(data[i]>0){
            posimult += data[i];
        }
        else{
           nagemult+=data[i];
        }
   }
   nagerata = Math.abs(nagemult) / (posimult + Math.abs(nagemult));
   nagerata = Math.round((nagerata +0.001)* Math.pow(10, 2)) / Math.pow(10, 2);
   $("#txt_njfzl").val(nagerata);

}
//********************gridview事件**********************//
var fun;
$(document).ready(fun = function () {
    initialBind();
    load();
    $("#GridView1 tr td").click(function () {
        // alert("aa");
        //        alert($(this).html());
        //        alert($(this).attr('id'));
        if (this.cellIndex == 0) {
            return;
        }
        var box = $(this).parent('tr').find('input[type=checkbox]');
                var checked = box.is(":checked"); //obj.parents('td:first').next();
                if (checked)
                    box.attr("checked", false);
                else
                    box.attr("checked", "checked");

        onCheckBoxClicked(box);

    });
    ///全选框全选和全不选
    $("#checkboxall").click(function () {
        if ($(this).attr('checked') == true) {//全选
            checkAllView();
        }
        else if ($(this).attr('checked') == false) {//全取消
            canselView();
            canselSpline();
            inter = null;
        }
    });

    ///复选框列表中某个复选框触发
    $("#GridView1 .checkone :input").click(function () {

        onCheckBoxClicked($(this));

    });

    function onCheckBoxClicked(obj) {

        //设置全选框状态
        $("#checkboxall").attr("checked", $("#GridView1 .checkone :input").length == $("#GridView1 .checkone :input:checked").length ? true : false);

        p = obj;
        if (obj.attr('checked') == true) {//复选框被选中，描一条曲线

            var ID = obj.parent().parent().parent().find(".jh").attr('value'); //对应的记录ID
            selectedIds.push(ID);

            if (selectedRadioValue == 'rblDuibi') {
                drawSingleSpline(ID); //描出对应曲线
            }
            else if (selectedRadioValue == 'rblSingle') {
                inter = obj;
                drawSingleSpline(ID); //描出对应曲线
                setTimeout("cancelSingleSpline()", 300);
                canselNoIndexView();
                //                cancelSingleSpline();

            }

        }
        else { //复选框取消，删除对应的曲线
            var ID = obj.parent().parent().parent().find(".jh").attr('value'); //对应的记录ID
            if (selectedIds.length > 0) {

                var temp = new Array(selectedIds.length - 1);
                var j = 0;
                for (var i = 0; i < selectedIds.length; i++) {

                    if (ID == selectedIds[i]) {
                        continue;
                    }
                    temp[j] = selectedIds[i];
                    j++;

                }
                selectedIds = temp;
                //selectedIds.pop();

            }
            num = Number(p.attr('title'));
            if (selectedRadioValue == 'rblSingle') {
                canselSpline();
            }
            else {
                cancelSingleSpline(); //取消曲线
            }
        }
    }


    //********************播放按钮事件**********************//

    ///给GridView1当前选中行变色
    $("#GridView1 tr:has(:checked)").addClass('selected');

    ///点击[下一条]触发事件
    $('#btn_next').click(function () {
        if (start_next == 1) {
            //让暂停按钮处于暂停状态
            $('#btn_start').val("  ");
            $('#btn_start').css("background", "url(../../images/DrawMult1/bf03.png) no-repeat");
            clearInterval(timer1);
            start_next = 0;
            canselSpline();
        }

        if (selectedRadioValue == "rblQushi") {//当前是趋势描图并且控制按钮处于激活状态
            if ($("#GridView1 .checkone :input:checked").length > 0) {
                if (inter != null) {
                    if ($("#GridView1 .checkone :input:checked").last().parent().parent().parent().find(".jh").attr('value') == inter.parent().parent().parent().find(".jh").attr('value')) {
                        cancelSingleSpline();
                        inter = null;

                    }
                }
                if (inter == null) {
                    //得到选中列表中的第一个checkbox对象
                    canselSpline();
                    inter = $("#GridView1 .checkone :input:checked").first();
                    inter.parent().parent().parent().addClass('selected').siblings().removeClass('selected').end()//当前行变色
                    strId = inter.parent().parent().parent().find(".jh").attr('value');
                    drawSingleSpline(strId);

                }
                else {//返回相对于inter的下一个checkbox
                    var find = false;
                    $("#GridView1 .checkone :input").each(function () {
                        if (find && $(this).attr('checked') == true) {
                            inter = $(this);
                            inter.parent().parent().parent().addClass('selected').siblings().removeClass('selected').end()//当前行变色
                            strId = inter.parent().parent().parent().find(".jh").attr('value');
                            cancelSingleSpline();
                            drawSingleSpline(strId);
                            //                            cancelSingleSpline();
                            return false;
                        }
                        if ($(this).parent().parent().parent().find(".jh").attr('value') == inter.parent().parent().parent().find(".jh").attr('value')) {
                            find = true;
                        }


                    }); //end of each

                } // end of else 
            } //end if
            else {
                alert("您还没有选择曲线");
            }
        }

    });
    //点击[上一条]触发事件
    $('#btn_previous').click(function () {
        if (start_next == 1) {
            //让暂停按钮处于暂停状态
            $('#btn_start').val("  ");
            $('#btn_start').css("background", "url(../../images/DrawMult1/bf03.png) no-repeat");
            clearInterval(timer1);
            start_next = 0;
            canselSpline();
        }
        if (selectedRadioValue == "rblQushi") {//当前是趋势描图并且控制按钮处于激活状态
            if ($("#GridView1 .checkone :input:checked").length > 0) {
                if (inter == null) {//如果第一次点击或者指针在第一条，则描最后一条
                    inter = $("#GridView1 .checkone :input:checked").last();
                    if (inter != null) {
                        cancelSingleSpline();
                    }

                    inter.parent().parent().parent().addClass('selected').siblings().removeClass('selected').end()//当前行变色
                    strId = inter.parent().parent().parent().find(".jh").attr('value');
                    drawSingleSpline(strId);
                }

                else {//返回相对于inter的上一个checkbox
                    var pre = null; //保存当前的上一条
                    $("#GridView1 .checkone :input").each(function () {
                        if ($(this).parent().parent().parent().find(".jh").attr('value') == inter.parent().parent().parent().find(".jh").attr('value')) {
                            if ($(this).parent().parent().parent().find(".jh").attr('value') == $("#GridView1 .checkone :input:checked").first().parent().parent().parent().find(".jh").attr('value')) {
                                inter = $("#GridView1 .checkone :input:checked").last();
                                inter.parent().parent().parent().addClass('selected').siblings().removeClass('selected').end()//当前行变色
                                strId = inter.parent().parent().parent().find(".jh").attr('value');
                                drawSingleSpline(strId);
                                cancelSingleSpline();
                                return false;
                            }
                            else if ($(this).parent().parent().parent().find(".jh").attr('value') == $("#GridView1 .checkone :input:checked").last().parent().parent().parent().find(".jh").attr('value')) {
                                inter = pre;
                                inter.parent().parent().parent().addClass('selected').siblings().removeClass('selected').end()//当前行变色
                                strId = inter.parent().parent().parent().find(".jh").attr('value');
                                drawSingleSpline(strId);
                                canselSpline();
                                return false;
                            }
                            else {
                                inter = pre;
                                inter.parent().parent().parent().addClass('selected').siblings().removeClass('selected').end()//当前行变色
                                strId = inter.parent().parent().parent().find(".jh").attr('value');
                                drawSingleSpline(strId);
                                cancelSingleSpline();
                                return false;
                            }
                        }
                        else if ($(this).attr('checked') == true) {
                            pre = $(this);
                        }
                    }); //end of each

                } // end of else 
            }
            else {
                alert("您还没有选择曲线");
            }
        }

    });
    ///暂停按钮点击事件
    $('#btn_start').click(function () {

        if (selectedRadioValue == "rblQushi") {
            if ($("#GridView1 .checkone :input:checked").length > 0) {
                if (inter == null)
                    inter = $("#GridView1 .checkone :input:checked").first();

                if ($(this).val() == "  ") {//"  "代表暂停," "代表播放
                    $(this).css("background", "url(../../images/DrawMult1/bf06.png) no-repeat");
                    $(this).val(" ");
                    var Tvalue = $("#amount").val(); //时间间隔
                    switch (Tvalue) {
                        case "1": INTERVAL = 1000; break;
                        case "2": INTERVAL = 2000; break;
                        case "3": INTERVAL = 3000; break;
                        case "4": INTERVAL = 4000; break;
                        case "5": INTERVAL = 5000; break;
                        case "6": INTERVAL = 6000; break;
                        case "7": INTERVAL = 7000; break;
                        case "8": INTERVAL = 8000; break;
                        case "9": INTERVAL = 9000; break;
                        case "10": INTERVAL = 10000; break;
                        default: INTERVAL = 2000;
                    }
                    drawQushiSpline();

                }
                else {

                    $(this).val("  ");
                    $(this).css("background", "url(../../images/DrawMult1/bf03.png) no-repeat");
                    clearInterval(timer1);
                    start_next = 1;
                }
            }
            else {
                alert("没有欲要描绘的曲线数据");
            }

        }

    });

    //最后一条按钮点击事件
    $('#btn_last').click(function () {
        if (selectedRadioValue == "rblQushi") {
            if ($("#GridView1 .checkone :input:checked").length > 0) {
                //让暂停按钮处于暂停状态
                $('#btn_start').val("  ");
                $('#btn_start').css("background", "url(../../images/DrawMult1/bf03.png) no-repeat");
                clearInterval(timer1);

                inter = $("#GridView1 .checkone :input:checked").last();
                canselSpline(); //清空曲线
                inter.parent().parent().parent().addClass('selected').siblings().removeClass('selected').end()//当前行变色
                strId = inter.parent().parent().parent().find(".jh").attr('value');
                drawSingleSpline(strId);
            }
            else {
                alert("没有欲要描绘的曲线数据");
            }
        }
    });

    //第一条按钮点击事件
    $('#btn_first').click(function () {

        if (selectedRadioValue == "rblQushi") {
            if ($("#GridView1 .checkone :input:checked").length > 0) {
                //让暂停按钮处于暂停状态
                $('#btn_start').val("  ");
                $('#btn_start').css("background", "url(../../images/DrawMult1/bf03.png) no-repeat");
                clearInterval(timer1);

                inter = $("#GridView1 .checkone :input:checked").first();
                canselSpline(); //清空曲线
                inter.parent().parent().parent().addClass('selected').siblings().removeClass('selected').end()//当前行变色
                strId = inter.parent().parent().parent().find(".jh").attr('value');
                drawSingleSpline(strId);
            }
            else {
                alert("没有欲要描绘的曲线数据");
            }
        }
    });
    //********************改变描图参数事件**********************//
    ///描图参数button点击事件
    $("#btn_HYGGL").click(function () {//有功功率
        drawCan = "HYGGL";

        $("#div_HYGGL").show();
        $("#div_HWGGL").hide();
        $("#div_HSZGL").hide();
        $("#div_HGLYS").hide();
        $("#div_ADL").hide();
        $("#div_ADY").hide();
        $("#div_DJSCNJ").hide();

        $(this).css("background-color", "yellow");
        $("#btn_HWGGL").css("background-color", "#00FFFF");
        $("#btn_HSZGL").css("background-color", "#00FFFF");
        $("#btn_HGLYS").css("background-color", "#00FFFF");
        $("#btn_ADL").css("background-color", "#00FFFF");
        $("#btn_ADY").css("background-color", "#00FFFF")
        $("#btn_DJSCNJ").css("background-color", "#00FFFF");
        $("#btn_SGT").css("background-color", "#00FFFF");
        if (selectedRadioValue == "rblQushi") {
            canselSpline();
        }
        else {
            canselSpline();
            drawSpline();
        }


    });
    $("#btn_HWGGL").click(function () {//无功功率
        drawCan = "HWGGL";

        $("#div_HWGGL").show();
        $("#div_HYGGL").hide();
        $("#div_HSZGL").hide();
        $("#div_HGLYS").hide();
        $("#div_ADL").hide();
        $("#div_ADY").hide();
        $("#div_DJSCNJ").hide();

        $(this).css("background-color", "yellow");
        $("#btn_HYGGL").css("background-color", "#00FFFF");
        $("#btn_HSZGL").css("background-color", "#00FFFF");
        $("#btn_HGLYS").css("background-color", "#00FFFF");
        $("#btn_ADL").css("background-color", "#00FFFF");
        $("#btn_ADY").css("background-color", "#00FFFF");
        $("#btn_DJSCNJ").css("background-color", "#00FFFF");
        $("#btn_SGT").css("background-color", "#00FFFF");
        if (selectedRadioValue == "rblQushi") {
            canselSpline();
        }
        else {
            canselSpline();
            drawSpline();
        }


    });
    $("#btn_HSZGL").click(function () {//视在功率
        drawCan = "HSZGL";

        $("#div_HSZGL").show();
        $("#div_HYGGL").hide();
        $("#div_HWGGL").hide();
        $("#div_HGLYS").hide();
        $("#div_ADL").hide();
        $("#div_ADY").hide();
        $("#div_DJSCNJ").hide();

        $(this).css("background-color", "yellow");
        $("#btn_HYGGL").css("background-color", "#00FFFF");
        $("#btn_HWGGL").css("background-color", "#00FFFF");
        $("#btn_HGLYS").css("background-color", "#00FFFF");
        $("#btn_ADL").css("background-color", "#00FFFF");
        $("#btn_ADY").css("background-color", "#00FFFF");
        $("#btn_DJSCNJ").css("background-color", "#00FFFF");
        $("#btn_SGT").css("background-color", "#00FFFF");
        if (selectedRadioValue == "rblQushi") {
            canselSpline();
        }
        else {
            canselSpline();
            drawSpline();
        }

    });
    $("#btn_HGLYS").click(function () {//功率因数
        drawCan = "HGLYS";

        $("#div_HGLYS").show();
        $("#div_HYGGL").hide();
        $("#div_HWGGL").hide();
        $("#div_HSZGL").hide();
        $("#div_ADL").hide();
        $("#div_ADY").hide();
        $("#div_DJSCNJ").hide();

        $(this).css("background-color", "yellow");
        $("#btn_HYGGL").css("background-color", "#00FFFF");
        $("#btn_HWGGL").css("background-color", "#00FFFF");
        $("#btn_HSZGL").css("background-color", "#00FFFF");
        $("#btn_ADL").css("background-color", "#00FFFF");
        $("#btn_ADY").css("background-color", "#00FFFF");
        $("#btn_DJSCNJ").css("background-color", "#00FFFF");
        $("#btn_SGT").css("background-color", "#00FFFF");
        if (selectedRadioValue == "rblQushi") {
            canselSpline();
        }
        else {
            canselSpline();
            drawSpline();
        }

    });
    $("#btn_ADL").click(function () {//电流
        drawCan = "ADL";

        $("#div_ADL").show();
        $("#div_HYGGL").hide();
        $("#div_HWGGL").hide();
        $("#div_HSZGL").hide();
        $("#div_HGLYS").hide();
        $("#div_ADY").hide();
        $("#div_DJSCNJ").hide();

        $(this).css("background-color", "yellow");
        $("#btn_HYGGL").css("background-color", "#00FFFF");
        $("#btn_HWGGL").css("background-color", "#00FFFF");
        $("#btn_HSZGL").css("background-color", "#00FFFF");
        $("#btn_HGLYS").css("background-color", "#00FFFF");
        $("#btn_ADY").css("background-color", "#00FFFF");
        $("#btn_DJSCNJ").css("background-color", "#00FFFF");
        $("#btn_SGT").css("background-color", "#00FFFF");
        if (selectedRadioValue == "rblQushi") {
            canselSpline();
        }
        else {
            canselSpline();
            drawSpline();
        }
    });
    $("#btn_ADY").click(function () {//电压
        drawCan = "ADY";
        $("#div_ADY").show();
        $("#div_HYGGL").hide();
        $("#div_HWGGL").hide();
        $("#div_HSZGL").hide();
        $("#div_HGLYS").hide();
        $("#div_ADL").hide();
        $("#div_DJSCNJ").hide();

        $(this).css("background-color", "yellow");
        $("#btn_HYGGL").css("background-color", "#00FFFF");
        $("#btn_HWGGL").css("background-color", "#00FFFF");
        $("#btn_HSZGL").css("background-color", "#00FFFF");
        $("#btn_HGLYS").css("background-color", "#00FFFF");
        $("#btn_ADL").css("background-color", "#00FFFF");
        $("#btn_DJSCNJ").css("background-color", "#00FFFF");
        $("#btn_SGT").css("background-color", "#00FFFF");
        if (selectedRadioValue == "rblQushi") {
            canselSpline();
        }
        else {
            canselSpline();
            drawSpline();
        }

    });
    $("#btn_DJSCNJ").click(function () {//扭矩
        drawCan = "DJSCNJ";
        $("#div_DJSCNJ").show();
        $("#div_HYGGL").hide();
        $("#div_HWGGL").hide();
        $("#div_HSZGL").hide();
        $("#div_HGLYS").hide();
        $("#div_ADY").hide();
        $("#div_ADL").hide();

        $(this).css("background-color", "yellow");
        $("#btn_HYGGL").css("background-color", "#00FFFF");
        $("#btn_HWGGL").css("background-color", "#00FFFF");
        $("#btn_HSZGL").css("background-color", "#00FFFF");
        $("#btn_HGLYS").css("background-color", "#00FFFF");
        $("#btn_ADL").css("background-color", "#00FFFF");
        $("#btn_ADY").css("background-color", "#00FFFF");
        $("#btn_SGT").css("background-color", "#00FFFF");
        if (selectedRadioValue == "rblQushi") {
            canselSpline();
        }
        else {
            canselSpline();
            drawSpline();
        }

    });
    $("#btn_SGT").click(function () {//示功图
        drawCan = "SGT";
        $("#div_DJSCNJ").hide();
        $("#div_HYGGL").hide();
        $("#div_HWGGL").hide();
        $("#div_HSZGL").hide();
        $("#div_HGLYS").hide();
        $("#div_ADY").hide();
        $("#div_ADL").hide();

        $(this).css("background-color", "yellow");
        $("#btn_HYGGL").css("background-color", "#00FFFF");
        $("#btn_HWGGL").css("background-color", "#00FFFF");
        $("#btn_HSZGL").css("background-color", "#00FFFF");
        $("#btn_HGLYS").css("background-color", "#00FFFF");
        $("#btn_ADL").css("background-color", "#00FFFF");
        $("#btn_ADY").css("background-color", "#00FFFF");
        $("#btn_DJSCNJ").css("background-color", "#00FFFF");
        if (selectedRadioValue == "rblQushi") {
            canselSpline();
        }
        else {
            canselSpline();
            drawSpline();
        }

        var chart = $('#container').highcharts();
        //        chart.setOptions({
        //            xAxis: {
        //                max: null,
        //                tickInterval: 20
        //            }
        //        });

        // chart.axes[0].max = null;

    });
    //********************改变描图方式事件**********************//
    ///触发描图方式，设置间隔曲线时间间隔
    $("input:radio[name = 'radiobutton']").change(function () {
        var val = $(this).val();
        if (val == 'rblQushi') {
            selectedRadioValue = 'rblQushi';

        }
        if (val == 'rblDuibi') {
            INTERVAL = 0;
            selectedRadioValue = 'rblDuibi';
        }
        if (val == 'rblSingle') {
            INTERVAL = 0;
            selectedRadioValue = 'rblSingle';
        }
    });

    $('#radio_qushi').click(function () {
        b = true;
        if ($('#radio_qushi').attr('checked') == true) {
            canselSpline();
            $("#checkboxall").attr("disabled", false);
            inter = null;
            b = true;

        }

    });
    $('#radio_duibi').click(function () {
        b = false;
        if ($('#radio_duibi').attr('checked') == true) {
            canselSpline();
            canselView();
            $("#checkboxall").attr("disabled", true);
            $("#checkboxall").attr("checked", false);

        }
    });
    $('#radio_single').click(function () {
        b = true;
        if ($('#radio_single').attr('checked') == true) {
            canselSpline();
            canselView();
            $("#checkboxall").attr("disabled", true);
            $("#checkboxall").attr("checked", false);

        }
    });

    ///描图控件属性设置
    $('#container').highcharts({
        colors: [
                 '#ff7e08',
                 '#fd230a',
                 '#fbbc01',
                 '#9ff0000',
                 '#1afd0e',
                 '#4929f0',
                 '#f28ff3',
                 '#77a1f5',
                 '#c4f505',
                 '#f6c90a'
             ],

        chart: {
            zoomType: 'x',
            type: 'spline',
            marginRight: 5,
            events: {
                load: function () {

                }
            }
        },
        xAxis: {
            max: null, //360,
            tickInterval: null
        },

        title: {
            text: '',
            x: -20 //center
        },
        subtitle: {
            text: '',
            x: -20
        },

        yAxis: {
            title: {
                text: ''
            },
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
            }]
        },
        tooltip: {
            valueSuffix: ''
        },
        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'middle',
            borderWidth: 0
        },
        plotOptions: {

            series: {
                animation: {
                    duration: 10
                }
            },

            spline: {
                lineWidth: 2,
                states: {
                    hover: {
                        lineWidth: 3
                    }
                },
                marker: {
                    enabled: false
                }

            }

        },
        series: []
    });


});


function load() {
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
}

function EndRequestHandler() {
    ///全选框全选和全不选
    $("#checkboxall").click(function () {
        if ($(this).attr('checked') == true) {//全选
            checkAllView();
        }
        else if ($(this).attr('checked') == false) {//全取消
            canselView();
            canselSpline();
            inter = null;
        }
    });

    if ($('#radio_duibi').attr('checked') == true) {
        $("#checkboxall").attr("disabled", true);
    }

    if ($('#radio_single').attr('checked') == true) {
        $("#checkboxall").attr("disabled", true);
    }


    function onCheckBoxClicked(obj) {

        //设置全选框状态
        $("#checkboxall").attr("checked", $("#GridView1 .checkone :input").length == $("#GridView1 .checkone :input:checked").length ? true : false);

        p = obj;
        if (obj.attr('checked') == true) {//复选框被选中，描一条曲线

            var ID = obj.parent().parent().parent().find(".jh").attr('value'); //对应的记录ID
            if (selectedRadioValue == 'rblDuibi') {
                drawSingleSpline(ID); //描出对应曲线

            }
            else if (selectedRadioValue == 'rblSingle') {
                inter = obj;
                canselNoIndexView();
                //                chart.series[0].remove();

                drawSingleSpline(ID); //描出对应曲线
                setTimeout("cancelSingleSpline()", 300);
                //                cancelSingleSpline();

            }

        }
        else { //复选框取消，删除对应的曲线

            cancelSingleSpline(); //取消曲线
        }
    }
    //某一行被选中
    $("#GridView1 tr td").click(function () {
        //        alert("aa");
        //        alert($(this).html());
        //        alert($(this).attr('id'));
        if (this.cellIndex == 0) {
            return;
        }
      
        var box = $(this).parent('tr').find('input[type=checkbox]');
        var checked = box.is(":checked"); //obj.parents('td:first').next();
        if (checked)
            box.attr("checked", false);
        else
            box.attr("checked", "checked");

        //gridview行区域被选中触发
        onCheckBoxClicked(box);

    });

    $("#GridView1 .checkone :input").click(function () {

        onCheckBoxClicked($(this));

    });

}
